﻿using ASP.NET5.Helper.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace ASP.NET5.Helper.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        /// <summary>
        /// 获取当前环境
        /// </summary>
        /// <returns>结果</returns>
        [HttpGet]
        public string CurrentEnvironment()
        {
            return AppsettingsHelper.CurrentEnvironment();
        }
        /// <summary>
        /// 是否生产环境
        /// </summary>
        /// <returns>结果</returns>
        [HttpGet]
        public bool IspProduction()
        {
            return AppsettingsHelper.IspProduction();
        }
        /// <summary>
        /// 根据环境获取配置文件路径
        /// </summary>
        /// <returns>结果</returns>
        [HttpGet]
        public string AppsettingsPath()
        {
            return AppsettingsHelper.AppsettingsPath;
        }
        /// <summary>
        /// 查询sql执行超时秒数CommandTimeout
        /// </summary>
        /// <returns>结果</returns>
        [HttpGet]
        public int CommandTimeout()
        {
            return AppsettingsHelper.CommandTimeout;
        }

        /// <summary>
        /// Environmen查询sql执行超时秒数CommandTimeout
        /// </summary>
        /// <returns>结果</returns>
        [HttpGet]
        public int EnvironmenCommandTimeout(string environmentName)
        {
            return Convert.ToInt32(AppsettingsHelper.Build(environmentName)["DefaultConfig:CommandTimeout"].ToString());
        }

        /// <summary>
        /// 获取指定节点ConnectionStrings下的某A库的连接字符串。
        /// </summary>
        /// <returns>结果</returns>
        [HttpGet]
        public string Connectionstrings()
        {
            return AppsettingsHelper.A;
        }


    }
}
